package org.jeecg.modules.rental.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.aspect.annotation.PermissionData;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.rental.entity.RentalPackageConfig;
import org.jeecg.modules.rental.service.IRentalPackageConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.security.MessageDigest;
import java.util.*;

/**
 * @Description: 租车套餐
 * @Author: sean
 * @Date:   2024-08-02
 * @Version: V1.0
 */
@Api(tags="租车套餐")
@RestController
@RequestMapping("/rental/package-config")
@Slf4j
public class RentalPackageConfigController extends JeecgController<RentalPackageConfig, IRentalPackageConfigService> {

	@Autowired
	private IRentalPackageConfigService rentalPackageConfigNewService;
	
	/**
	 * 分页列表查询
	 *
	 * @param rentalPackageConfigNew
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	//@AutoLog(value = "rental_package_config_new-分页列表查询")
	@ApiOperation(value="rental_package_config_new-分页列表查询", notes="rental_package_config_new-分页列表查询")
	@GetMapping(value = "/list")
	@PermissionData(pageComponent="rental/package/configlist")
	public Result<IPage<RentalPackageConfig>> queryPageList(RentalPackageConfig rentalPackageConfigNew,
															@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
															@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
															HttpServletRequest request) {
		QueryWrapper<RentalPackageConfig> queryWrapper = QueryGenerator.initQueryWrapper(rentalPackageConfigNew, request.getParameterMap());
		Page<RentalPackageConfig> page = new Page<RentalPackageConfig>(pageNo, pageSize);
		IPage<RentalPackageConfig> pageList = rentalPackageConfigNewService.selectJoinPage(page, queryWrapper);
		return Result.OK(pageList);
	}


	 /**
	  * 租车套餐
	  * @return
	  */
	 @ApiOperation(value="rental_package_config_new-列表查询", notes="租车套餐")
	 @GetMapping(value = "/rental-configs")
	 public Result<List<RentalPackageConfig>> rentalConfigs(Long carTypeId) {
		 List<RentalPackageConfig> list = rentalPackageConfigNewService.rentalConfigNews(carTypeId);
		 return Result.OK(list);
	 }

	/**
	 * 续租套餐
	 * @return
	 */
	@ApiOperation(value="rental_package_config_new-列表查询", notes="续租套餐")
	@GetMapping(value = "/renew-configs")
	public Result<List<RentalPackageConfig>> renewConfigs(Long carTypeId) {
		List<RentalPackageConfig> list = rentalPackageConfigNewService.renewConfigNews(carTypeId);
		return Result.OK(list);
	}
	
	/**
	 *   添加
	 *
	 * @param rentalPackageConfigNew
	 * @return
	 */
	@AutoLog(value = "rental_package_config_new-添加")
	@ApiOperation(value="rental_package_config_new-添加", notes="rental_package_config_new-添加")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody RentalPackageConfig rentalPackageConfigNew) {
		rentalPackageConfigNewService.save(rentalPackageConfigNew);
		return Result.OK("common.add.success");
	}
	
	/**
	 *  编辑
	 *
	 * @param rentalPackageConfigNew
	 * @return
	 */
	@AutoLog(value = "rental_package_config_new-编辑")
	@ApiOperation(value="rental_package_config_new-编辑", notes="rental_package_config_new-编辑")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody RentalPackageConfig rentalPackageConfigNew) {
		rentalPackageConfigNewService.updateById(rentalPackageConfigNew);
		return Result.OK("common.edit.success");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "rental_package_config_new-通过id删除")
	@ApiOperation(value="rental_package_config_new-通过id删除", notes="rental_package_config_new-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		rentalPackageConfigNewService.removeById(id);
		return Result.OK("common.delete.success");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "rental_package_config_new-批量删除")
	@ApiOperation(value="rental_package_config_new-批量删除", notes="rental_package_config_new-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.rentalPackageConfigNewService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("common.delete.batch.success");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "rental_package_config_new-通过id查询")
	@ApiOperation(value="rental_package_config_new-通过id查询", notes="rental_package_config_new-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<RentalPackageConfig> queryById(@RequestParam(name="id",required=true) String id) {
		RentalPackageConfig rentalPackageConfigNew = rentalPackageConfigNewService.getById(id);
		if(rentalPackageConfigNew==null) {
			return Result.error("common.query.not.found",null);
		}
		return Result.OK(rentalPackageConfigNew);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param rentalPackageConfigNew
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, RentalPackageConfig rentalPackageConfigNew) {
        return super.exportXls(request, rentalPackageConfigNew, RentalPackageConfig.class, "rental_package_config_new");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, RentalPackageConfig.class);
    }

}
